#include <stdio.h>

long atol(char*);

int main(){

    char *data = "-123456";
    printf("%d\n", atol(data));

    return 0;
}

long atol(char *p){
    char *s = p;
    int neg = 0;
    switch(*s){
        case '-':{
            neg = 1;
            s++;
        }break;
        case '+': {
            s++;
        }break;
        default:
            break;
    }

    long r = 0;
    while(*s >= '0' && *s <= '9'){

        int t = *s++ - '0';
        if(neg){
            t = -t;
        }
        r = r * 10 + t;
    }
    return r;
}